package com.chif.goingplus.controller;

import com.chif.goingplus.pojo.Client;
import com.chif.goingplus.service.ClientService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private ClientService clientService;


    @RequestMapping("/create")
    public String createClient(Client client){
        return clientService.createClient(client)+"";
    }

    @RequestMapping("/add")
    public String addClient(Client client){
        return clientService.addClient(client)+"";
    }

    @RequestMapping("/delete")
    public String deleteClientById(int id){
        clientService.deleteClientById(id);
        return "删除会员信息成功";
    }

    @RequestMapping("/update")
    public String updateClient(Client client){
        clientService.updateClient(client);
        return "会员信息提交修改成功";
    }

    @RequestMapping("/query")
    public String queryClientById(int id){
        return JsonUtils.getJson(clientService.queryClientById(id));
    }

    @RequestMapping("/queryAll")
    public String queryAllClient(){
        return JsonUtils.getJson(clientService.queryAllClient());
    }

    @RequestMapping("/queryClientByName")
    public String queryClientByName(String name){
        return JsonUtils.getJson(clientService.queryClientByName(name));
    }
}
